/*
* Copyright (C) 2004-2011  Autodesk, Inc.
* 
* This library is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser
* General Public License as published by the Free Software Foundation.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*
*/

#include "stdafx.h"
#include "FdoCMSSpatialContextReader.h"
#include "FdoCMSGlobals.h"

FdoCMSSpatialContextReader::FdoCMSSpatialContextReader()
: mIndex (-1)
{
}

FdoCMSSpatialContextReader::~FdoCMSSpatialContextReader()
{
}

FdoString* FdoCMSSpatialContextReader::GetName()
{
    return FdoCMSGlobals::DefaultEPSGCode;
}

FdoString* FdoCMSSpatialContextReader::GetDescription()
{
    return L"";
}

FdoString* FdoCMSSpatialContextReader::GetCoordinateSystem()
{
    return FdoCMSGlobals::DefaultEPSGCode;
}

FdoString* FdoCMSSpatialContextReader::GetCoordinateSystemWkt()
{
    // A WKT shall not be supplied for CMS spatial context definitions. 
    return L"";
}

FdoSpatialContextExtentType FdoCMSSpatialContextReader::GetExtentType()
{
    return (FdoSpatialContextExtentType_Static);
}

FdoByteArray* FdoCMSSpatialContextReader::GetExtent()
{
    FdoDouble ordinates[10];
    ordinates[0] = -180;
    ordinates[1] = -90;
    ordinates[2] = 180;
    ordinates[3] = -90;
    ordinates[4] = 180;
    ordinates[5] = 90;
    ordinates[6] = -180;
    ordinates[7] = 90;
    ordinates[8] = -180;
    ordinates[9] = -90;

    FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance();
    FdoPtr<FdoILinearRing> linearRing = gf->CreateLinearRing(FdoDimensionality_XY, 10, ordinates);
    FdoPtr<FdoIPolygon> polygon = gf->CreatePolygon(linearRing, NULL);

    return gf->GetFgf(polygon);
}

const double FdoCMSSpatialContextReader::GetXYTolerance()
{
    return (0.001);
}

const double FdoCMSSpatialContextReader::GetZTolerance()
{
    return (0.001);
}

const bool FdoCMSSpatialContextReader::IsActive()
{
    // TODO:
    return false;
}

bool FdoCMSSpatialContextReader::ReadNext()
{
    const FdoSize size = 1;
    return (++mIndex < size);
}

void FdoCMSSpatialContextReader::Dispose()
{
    delete this;
}
